package com.teckteam.ptvsystem.view;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.teckteam.ptvsystem.controller.GeocodeResultsML;

/**
 * Representation of row elements in geocoding results "table"
 *
 */
public class GeocodeResultRowPanel extends JPanel
{
   private JLabel addrLabel, rankLabel, latLonLabel; 
   private GeocodePrompt gp;
   /**
    * Constructor to populate the JPanel from scraped data.
    * 
    * @param args
    * @param geocodePrompt 
    */
   public GeocodeResultRowPanel(String[] args, GeocodePrompt gp)
   {
      //Args format: 0:address, 1:accuracyrank, 2:suburb, 3:latitude, 4:longitude
      addrLabel = new JLabel(String.format("       %s, %s", args[0], args[2]));
      rankLabel = new JLabel(args[1]);
      latLonLabel = new JLabel(String.format("%s %s", args[3], args[4]));
      this.gp = gp;
      
      //Mouse actions
      addMouseListener(new GeocodeResultsML(this));
      
      setLayout(new BorderLayout());
      setBorder(BorderFactory.createLineBorder(Color.BLACK));
      JPanel coord = new JPanel();
      
      coord.add(latLonLabel);
      
      coord.setBackground(Color.YELLOW);
      add(rankLabel, BorderLayout.WEST);
      add(addrLabel, BorderLayout.CENTER);
      add(coord, BorderLayout.EAST);
   }
   
   /**
    * Collect GPS coordinates attached to panel row and pass it to parent dialog.
    */
   public void setGPSCoords()
   {
      String coords[] = latLonLabel.getText().split("\\s"); 
      gp.setGPSCoords(coords[0], coords[1], addrLabel.getText().trim());
   }
   
}
